package com.punch.user.controller;


import com.punch.common.dto.login.AppLoginUserDTO;
import com.punch.common.dto.user.guardian.AppSaveStudentDTO;
import com.punch.common.dto.user.user.PlatformUserDTO;
import com.punch.common.model.LoginUser;
import com.punch.common.model.Result;
import com.punch.common.vo.user.user.PlatformUserVO;
import com.punch.user.service.PlatformUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 平台用户 前端控制器
 * </p>
 *
 * @author wjj
 * @since 2020-12-03
 */
@RestController
public class PlatformUserController {

    @Resource
    private PlatformUserService platformUserService;


    /**
     * 平台用户登录,不存在则注册
     *
     * @param appLoginUserDTO 平台用户表单
     */
    @PostMapping(value = "/app-user")
    public void saveOrUpdatePlatformUser(@RequestBody AppLoginUserDTO appLoginUserDTO) {
        platformUserService.saveOrUpdatePlatformUser(appLoginUserDTO);
    }

    /**
     * 通过手机号查找手机用户信息
     *
     * @param mobile 手机号码
     * @return loginUser
     */
    @GetMapping(value = "/app-user/mobile", params = "mobile")
    public LoginUser getUserByMobile(@RequestParam("mobile") String mobile) {
        return platformUserService.getUserByMobile(mobile);
    }


    /**
     * 平台用户忘记密码
     *
     * @param appLoginUserDTO 平台用户表单
     */
    @PostMapping(value = "/app-user/pwd-forget")
    public Boolean forgetUserPwd(@RequestBody AppLoginUserDTO appLoginUserDTO) {
        return platformUserService.forgetUserPwd(appLoginUserDTO);
    }

    /**
     * 获取app登录用户信息
     *
     * @return PlatformUserVO
     */
    @GetMapping(value = "/app-user", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "获取app登录用户信息", notes = "获取app登录用户信息", produces = "application/json")
    public Result<PlatformUserVO> getLoginUser() {
        return Result.succeed(platformUserService.getLoginUser());
    }


    /**
     * 修改app用户信息
     *
     * @param platformUserDTO 用户修改表单
     * @return 用户uid
     */
    @PutMapping(value = "/app-user", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "修改app用户信息", notes = "修改app用户信息", produces = "application/json")
    public Result<Void> updatePlatformUser(@RequestBody PlatformUserDTO platformUserDTO) {
        platformUserService.updatePlatformUser(platformUserDTO);
        return Result.succeed("修改成功");
    }

}
